require "import"
import "android.app.*"
import "android.os.*"
import "android.widget.*"
import "android.view.*"
import "layout"
--activity.setTitle(Manalua+)
activity.setTheme(android.R.style.Theme_Material_Light_NoActionBar)
activity.setContentView(loadlayout(layout))

import "java.io.FileInputStream"
import "java.io.FileOutputStream"
import "java.util.zip.ZipOutputStream"

local path = "/sdcard/kk.mpkg"--MPKG转ZIP输入
local out = "/sdcard/kk.zip"--MPKG转ZIP输出
local fis = FileInputStream(path)
local zos = ZipOutputStream(FileOutputStream(out))
local bit = require "bit32"

function readInt()
    local bytes = byte[4]
    fis.read(bytes)
    return (bytes[0] & 0xFF | bytes[1] << 8 & 0xFFFF | bit.rshift(bytes[2] << 24, 8) | bytes[3] << 24)
end

function readData(length)
    local bytes = byte[length]
    fis.read(bytes)
    return bytes
end
--版本号
print(String(readData(readInt())))
local filenum = readInt()
local dataTable = {}
local lengthTable = {}
for i = 1, filenum do
    dataTable[i] = String(readData(readInt()))
    readInt()
    lengthTable[i] = readInt()
end

import "java.util.zip.ZipEntry"
for i = 1, #dataTable do
    zos.putNextEntry(ZipEntry(dataTable[i]))
    zos.write(readData(lengthTable[i]))
    zos.closeEntry()
end
fis.close()
zos.close()
print("完成")